/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.adsi.Vista;

import com.adsi.logica.LogicaConsignacionLocal;
import com.adsi.logica.LogicaCuentasLocal;
import com.adsi.logica.LogicaRetirosLocal;
import com.adsi.logica.LogicaUsuariosLocal;
import com.adsi.modelo.Cuentas;
import com.adsi.modelo.Retiros;
import java.io.Serializable;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.primefaces.model.chart.Axis;
import org.primefaces.model.chart.AxisType;
import org.primefaces.model.chart.BubbleChartModel;
import org.primefaces.model.chart.BubbleChartSeries;

/**
 *
 * @author cristhian
 */
@ManagedBean(name = "Graficar")
@RequestScoped

public class Bubble implements Serializable {

    @EJB
    private LogicaRetirosLocal logicaRetiro;

    private BubbleChartModel bubbleModel1;

    public BubbleChartModel getBubbleModel1() {
        return bubbleModel1;
    }

    public void setBubbleModel1(BubbleChartModel bubbleModel1) {
        this.bubbleModel1 = bubbleModel1;
    }

    @PostConstruct
    public void init() {
        createBubbleModels();
    }

    private void createBubbleModels() {
        bubbleModel1 = initBubbleModel();
        bubbleModel1.setTitle("Retiros");
        bubbleModel1.getAxis(AxisType.X).setLabel("Price");
        Axis yAxis = bubbleModel1.getAxis(AxisType.Y);
        yAxis.setMin(0);
        yAxis.setMax(1000000);
        yAxis.setLabel("Monto");

    }

    public LogicaRetirosLocal getLogicaRetiro() {
        return logicaRetiro;
    }

    public void setLogicaRetiro(LogicaRetirosLocal logicaRetiro) {
        this.logicaRetiro = logicaRetiro;
    }

   
    private BubbleChartModel initBubbleModel() {
        BubbleChartModel model = new BubbleChartModel();
        try {

            List<Retiros> lista = logicaRetiro.consultar();
            for (int i = 0; i < lista.size(); i++) {
                model.add(new BubbleChartSeries(lista.get(i).getRetDescripcion(), 10+i,  lista.get(i).getRetValor().intValue(),lista.get(i).getUsuCedula().getUsuCedula().intValue()));
            }

        } catch (Exception ex) {
            Logger.getLogger(Bubble.class.getName()).log(Level.SEVERE, null, ex);
        }
        return model;
    }

}
